package com.ship.boats.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ship.boats.domain.SpBoatsSisterManage;
import com.ship.boats.domain.vo.QueryBoatsSisterInfo;
import com.ship.boats.mapper.SpBoatsSisterManageMapper;
import com.ship.boats.service.BoatsArchivesService;
import com.ship.boats.service.SpBoatsSisterManageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>SpBoatsSisterManageServiceImpl</b>
 *
 * @description: SpBoatsSisterManageServiceImpl <br>
 * @date: 2024/4/7 16:31 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class SpBoatsSisterManageServiceImpl extends ServiceImpl<SpBoatsSisterManageMapper, SpBoatsSisterManage> implements SpBoatsSisterManageService {
    private static final Logger logger = LoggerFactory.getLogger(SpBoatsSisterManageServiceImpl.class);

    @Override
    public void renewalSisterShipByImo(List<SpBoatsSisterManage> sisterShips) {
        if (CollectionUtil.isNotEmpty(sisterShips)){
            sisterShips.forEach(item -> {
                QueryWrapper queryWrapper = new QueryWrapper();
                queryWrapper.eq("sister_imo",item.getSisterImo());
                queryWrapper.eq("imo",item.getImo());
                SpBoatsSisterManage spBoatsSisterManage = baseMapper.selectOne(queryWrapper);
                if (spBoatsSisterManage == null){
                    baseMapper.insert(item);
                }
            });
        }
    }

    @Override
    public List<String> queryBoatsSisterList(String imo) {
        //查询所有姊妹船imo号
        List<String> imoList = baseMapper.queryImoList(imo);
//        List<QueryBoatsSisterInfo> list = baseMapper.queryBoatsSisterList(imo);
        return imoList;
    }

    @Override
    public String querySisterBoateName(String imo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("enable","1");
        queryWrapper.eq("imo",imo);
        List<SpBoatsSisterManage> list = baseMapper.selectList(queryWrapper);
        if (CollectionUtil.isNotEmpty(list)){
            return list.get(0).getShipName();
        }
        return null;
    }
}
